@extends('admin.public.header')
@section('title','退货地址列表')

@section('listsearch')

@endsection

@section('listcontent')

<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<!-- 表头左侧按钮 -->
<script type="text/html" id="toolbarColumn">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layuimini-btn-primary" onclick="window.location.reload();" ><i class="layui-icon layui-icon-refresh-3"></i></button>
        <button class="layui-btn layui-btn-primary layui-btn-sm layui-border-blue" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary layui-border-red" lay-event="batch_delete"><i class="layui-icon layui-icon-delete"></i>批量删除</button> 
    </div>
</script>
<!-- 操作按钮 -->
<script type="text/html" id="barOperate">
    <a class="layui-btn layui-btn-xs layui-btn-primary layui-border-blue" lay-event="edit"><i class="layui-icon"></i>编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-primary layui-border-red" lay-event="delete"><i class="layui-icon"></i>删除</a>
</script>
@endsection

@section('listscript')
<script type="text/javascript">
    layui.use(['form','table','miniTab','laydate','laytpl'], function(){
        var table = layui.table, $=layui.jquery, form = layui.form , miniTab = layui.miniTab, laydate = layui.laydate , laytpl = layui.laytpl;
        miniTab.listen();
        
        // 渲染表格
        table.render({
                elem: '#tableList',
                url:'/admin/refund_address/ajaxList',
                parseData: function(res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": res.data.list //解析数据列表
                    }
                },
                cellMinWidth: 50,//全局定义常规单元格的最小宽度
                toolbar: '#toolbarColumn',//开启头部工具栏，并为其绑定左侧模板
                defaultToolbar: [],
            title: '退货地址列表',
            cols: [[
                {type: 'checkbox', align: 'center'},
                {field:'id', title:'ID', width:80, align: 'center', unresize: true},
                {field:'name', title:'姓名', align: 'center', unresize: true},
                {field:'mobile', title:'联系电话', align: 'center', unresize: true},
                {field:'address', title:'收获地址', align: 'center', unresize: true},
                
                {title:'操作', toolbar:'#barOperate', width:180, align: 'center'}
            ]],
            id: 'listReload',
            limits: [15, 20, 30, 50, 100,200],
            limit: 15,
            page: true,
            text: {
                none: '抱歉！暂无数据~' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });
        
        //头工具栏事件
        table.on('toolbar(tableList)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var ids = [];
            var data = checkStatus.data;
            for (var i=0;i<data.length;i++){
                ids.push(data[i].id);
            }
            switch(obj.event){
                case 'add':
                    var index = layer.open({
                        title: '新增退货地址',
                        type: 2,
                        shade: 0.2,
                        maxmin:true,
                        shadeClose: true,
                        area: ['95%', '95%'],
                        skin: 'layui-layer-lan',
                        content: '/admin/refund_address/edit',
                    });
                break;
                case 'batch_delete':
                    layer.confirm('确定将选中的数据删除吗？', {
                    title : "操作确认",
                    skin: 'layui-layer-lan'
                    },function(index){
                        $.ajax({
                            url:'/admin/refund_address/batchDelete',
                            type:'post',
                            data:{'id':ids},
                            dataType:"JSON",
                            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                            success:function(data){
                                if(data.code == 0){
                                    layer.msg(data.message,{icon: 1,time:1500},function(){
                                        setTimeout('window.location.reload()',500);
                                    });
                                }
                                else{
                                    layer.msg(data.message,{icon: 2});
                                }
                            },
                            error:function(e){
                                layer.msg(data.message,{icon: 2});
                            },

                        });
                    });
                break;
                
                //自定义头工具栏右侧图标 - 提示
                case 'TABLE_SEARCH':
                    var display = $(".table-search-fieldset").css("display"); //获取标签的display属性
                    if(display == 'none'){
                        $(".table-search-fieldset").show();
                    }else{
                        $(".table-search-fieldset").hide();
                    }
                break;
               
            };
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'edit'){//订单详情
                var index = layer.open({
                    title: '编辑退货地址',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['95%', '95%'],
                    skin: 'layui-layer-lan',
                    content: '/admin/refund_address/edit?id='+id,
                });
            }else if(obj.event === 'delete'){//删除订单
                layer.confirm('确定删除该退货地址吗？', {
                    title : "操作确认",
                    skin: 'layui-layer-lan'
                },function(index){
                    $.ajax({
                        url:'/admin/refund_address/delete',
                        type:'post',
                        data:{'id':id},
                        dataType:"JSON",
                        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                        success:function(data){
                            if(data.code == 0){
                                layer.msg(data.message,{icon: 1,time:1500},function(){
                                    setTimeout('window.location.reload()',500);
                                });
                            }
                            else{
                                layer.msg(data.message,{icon: 2});
                            }
                        },
                        error:function(e){
                            layer.msg(data.message,{icon: 2});
                        },
                        
                    });
                    layer.close(index);
                });
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //var result = JSON.stringify(data.field);
            
            //执行搜索重载
            table.reload('listReload', {
                where: {
                    nickname: $("#nickname").val(),
                    
                }
            });
            return false;
        });

        // 监听重置操作
        form.on('submit(data-reset-btn)', function (data) {
            $("#nickname").val('');
            
            form.render();
        });

    });
</script>
@endsection
